﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Snake.Vue
{
    public partial class FormConnexion : Form
    {
        private MainVue parent = new MainVue();

        public FormConnexion(MainVue form1)
        {
            InitializeComponent();
            this.parent = form1;
        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }


        private void Serveur_Click(object sender, EventArgs e)
        {
            Console.Write("test");

            if (this.AddresseServeur.Visible != true)
            {

                this.labserv.Visible = false;
                this.ReceptionServ.Visible = false;
                this.AddresseServeur.Visible = true;

                //Récupération information serveur.
                string s = Dns.GetHostName(); // obtenir le nom de son ordinateur
                this.textBox1.Text = "serveur";
                IPHostEntry he = Dns.GetHostEntry(s);
                IPAddress[] tipa = he.AddressList;
                Console.Write("Addresse ip :" + tipa[3]);
                this.AddresseServeur.Text ="Addresse ip Serv : " +tipa[3].ToString();
            }
        }

        private void Client_Click(object sender, EventArgs e)
        {
           
            if (this.ReceptionServ.Visible != true && this.labserv.Visible != true)
            {
                this.textBox1.Text = "client";
                this.ReceptionServ.Visible = false;
                this.ReceptionServ.Text = "127.0.0.1";
                this.labserv.Visible = true ;
                this.ReceptionServ.Visible = true;

            }
        }
        private void Valider_Click(object sender, EventArgs e)
        {
            if ((this.Client.Checked == true && this.Serveur.Checked != true) || (this.Client.Checked != true && this.Serveur.Checked == true))
            {
                if (this.Client.Checked == true)
                {   
                    parent.Type="Client";
                    parent.Nom = this.textBox1.Text;
                    parent.ip = this.ReceptionServ.Text;
                    this.Close();
                }
                else if (this.Serveur.Checked == true)
                {
                    parent.Type = "Serveur";
                    parent.Nom = this.textBox1.Text;
                    this.Close();
                }
            }
        }

    
    }
}
